﻿
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SolidworksDLL;


namespace YeTestExe
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SolidWorksHelp.Testc();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            bool b =   SolidWorksHelp.GetSwApp();
            if (b )
            {
                MessageBox.Show("获取成功");
            }
            else 
            {
                MessageBox.Show("Solidworks未可打开，获取失败");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetFristSolidWorksRunningObject();
            if (b)
            {
                MessageBox.Show("获取成功");
            }
            else
            {
                MessageBox.Show("Solidworks未可打开，获取失败");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
           MessageBox.Show( SolidWorksHelp.GetSwAppPath());

        }

        private void button5_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.OpenSwApp ();
            if (b)
            {
                MessageBox.Show("获取成功");
            }
            else
            {
                MessageBox.Show("Solidworks未可打开，获取失败");
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwApp();    //第一步先获取到swapp
            if (false == b)
            {
                MessageBox.Show("获取失败");
                return;
            }
            textBox1.Text = TestSw.GerPath() + "("  +TestSw.GetVer() + ")";
            //MessageBox.Show(TestSw.GetVer());

        }

        private void button7_Click(object sender, EventArgs e)
        {
            Button button = (Button)sender;
            int myState;
            string a = button.Text;
            if ("窗口最大化" == a)
            {
                myState = 1;
            }
            else if  ("窗口最小化" == a)
              
            {
                myState = 2;
             }
            else
            {
                myState = 0;
            }

            bool b = SolidWorksHelp.GetSwApp();    //第一步先获取到swapp
            if (false == b)
            {
                MessageBox.Show("获取失败");
                return;
            }
           
            TestSw.MakeWindowSate(myState);

        }

        private void button10_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwApp();
            if (false == b )
            {
                MessageBox.Show("获取sw失败！");
                return;
            }

            string tempPath = @"C:\模板\英普瑞\" + comboBox1.Text;
            string result  = ModelDocHelp.NewDocumnet(tempPath);

            if (result == "" )
            {
                MessageBox.Show("创建零件成功");                
            }
            else
            {
                MessageBox.Show(result);
            }

        }

        private void button11_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwApp();
            if (false == b)
            {
                MessageBox.Show("获取sw失败！");
                return;
            }

            string partPath = @"D:\系统\Desktop\零件库试验\试验零件-001.sldprt" ;
            string result = ModelDocHelp.SaveDoc(partPath);

            if (result == "")
            {
                MessageBox.Show("保存零件成功");
            }
            else
            {
                MessageBox.Show(result);
            }
        }

        private void button12_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwApp();
            if (false == b)
            {
                MessageBox.Show("获取sw失败！");
                return;
            }

            string partPath = @"D:\系统\Desktop\零件库试验\新建文件夹\试验零件-001.sldprt";
            string result = ModelDocHelp.OpenDoc (partPath);

            if (result == "")
            {
                MessageBox.Show("打开零件成功");
            }
            else
            {
                MessageBox.Show(result);
            }
        }

        private void button13_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwApp();
            if (false == b)
            {
                MessageBox.Show("获取sw失败！");
                return;
            }
            List<string> modelPaths = ModelDocHelp.GetAllDoc();
            foreach (var item in modelPaths)
            {
                textBox2.AppendText(Environment.NewLine + item);
            }
        }

        private void button14_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwApp();
            if (false == b)
            {
                MessageBox.Show("获取sw失败！");
                return;
            }
            string str = ModelDocHelp.GetActiveDoc();
            textBox2.AppendText(Environment.NewLine + str);

        }

        private void button15_Click(object sender, EventArgs e)
        {
            bool b = SolidWorksHelp.GetSwApp();
            if (false == b)
            {
                MessageBox.Show("获取sw失败！");
                return;
            }
            string str = ModelDocHelp.GetEditTarget();
            textBox2.AppendText(Environment.NewLine + str);
        }

        private void button16_Click(object sender, EventArgs e)
        {
            OpenAsmGetAllPartPath OpenPath = new OpenAsmGetAllPartPath();
            OpenPath.Show();
        }

        private void button17_Click(object sender, EventArgs e)
        {
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {
          
        }
    }
}
